package com.ruoyi.btlfbreed.service.impl;

import java.util.List;

import com.ruoyi.btlfbreed.domain.TbChickens;
import com.ruoyi.btlfbreed.mapper.TbChickensMapper;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.btlfbreed.mapper.TbChickenOutRegistryMapper;
import com.ruoyi.btlfbreed.domain.TbChickenOutRegistry;
import com.ruoyi.btlfbreed.service.ITbChickenOutRegistryService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 肉鸡出栏Service业务层处理
 * 
 * @author codeman
 * @date 2024-05-07
 */
@Service
public class TbChickenOutRegistryServiceImpl implements ITbChickenOutRegistryService 
{
    @Autowired
    private TbChickenOutRegistryMapper tbChickenOutRegistryMapper;
    @Autowired
    private TbChickensMapper tbChickensMapper;
    /**
     * 查询肉鸡出栏
     * 
     * @param id 肉鸡出栏主键
     * @return 肉鸡出栏
     */
    @Override
    public TbChickenOutRegistry selectTbChickenOutRegistryById(Long id)
    {
        return tbChickenOutRegistryMapper.selectTbChickenOutRegistryById(id);
    }

    /**
     * 查询肉鸡出栏列表
     * 
     * @param tbChickenOutRegistry 肉鸡出栏
     * @return 肉鸡出栏
     */
    @Override
    public List<TbChickenOutRegistry> selectTbChickenOutRegistryList(TbChickenOutRegistry tbChickenOutRegistry)
    {
        return tbChickenOutRegistryMapper.selectTbChickenOutRegistryList(tbChickenOutRegistry);
    }

    /**
     * 新增肉鸡出栏
     * 
     * @param tbChickenOutRegistry 肉鸡出栏
     * @return 结果
     */
    @Transactional
    @Override
    public int insertTbChickenOutRegistry(TbChickenOutRegistry tbChickenOutRegistry)
    {
        tbChickenOutRegistry.setCreateTime(DateUtils.getNowDate());
        TbChickens tbChickens=new TbChickens();
        tbChickens.setIsSold("Y");
        tbChickens.setChickenId(tbChickenOutRegistry.getChickenId());
        tbChickensMapper.updateTbChickens(tbChickens);
        return tbChickenOutRegistryMapper.insertTbChickenOutRegistry(tbChickenOutRegistry);
    }

    /**
     * 修改肉鸡出栏
     * 
     * @param tbChickenOutRegistry 肉鸡出栏
     * @return 结果
     */

    @Transactional
    @Override
    public int updateTbChickenOutRegistry(TbChickenOutRegistry tbChickenOutRegistry)
    {
        tbChickenOutRegistry.setUpdateTime(DateUtils.getNowDate());
        return tbChickenOutRegistryMapper.updateTbChickenOutRegistry(tbChickenOutRegistry);
    }

    /**
     * 批量删除肉鸡出栏
     * 
     * @param ids 需要删除的肉鸡出栏主键
     * @return 结果
     */
    @Override
    @Transactional
    public int deleteTbChickenOutRegistryByIds(Long[] ids)
    {
        return tbChickenOutRegistryMapper.deleteTbChickenOutRegistryByIds(ids);
    }

    /**
     * 删除肉鸡出栏信息
     * 
     * @param id 肉鸡出栏主键
     * @return 结果
     */
    @Transactional
    @Override

    public int deleteTbChickenOutRegistryById(Long id)
    {
        TbChickenOutRegistry tbChickenOutRegistry=new TbChickenOutRegistry();
        tbChickenOutRegistry= tbChickenOutRegistryMapper.selectTbChickenOutRegistryById(id);
        TbChickens tbChickens=new TbChickens();
        tbChickens.setIsSold("N");
        tbChickens.setChickenId(tbChickenOutRegistry.getChickenId());
        tbChickensMapper.updateTbChickens(tbChickens);
        return tbChickenOutRegistryMapper.deleteTbChickenOutRegistryById(id);
    }
}
